#include "mainwindow.h"
#include "CanRoute.h"
#include "ActionConsumer.h"
#include "./ui_mainwindow.h"
#include "multiscreen.h"
#include "logupload.h"

#include <qDebug>
#include <QKeyEvent>
#include <QFileDialog>
#include <QApplication>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , itsTimer(new QTimer(this)), itsOnlineTimer(new QTimer(this)), itsRefreshUiTimer(new QTimer(this))
{
    ui->setupUi(this);

    itsOnlineTimer->connect(itsOnlineTimer, &QTimer::timeout, this, &MainWindow::onCheckOnlineTimeout);
    itsOnlineTimer->start(500);
    itsRefreshUiTimer->start(20);

    ActionConsumer::getInstance()->pushBackAction(createCanAction("LftTrnLmpAtv", 0));
    ActionConsumer::getInstance()->pushBackAction(createSleepAction(500));
    ActionConsumer::getInstance()->pushBackAction(createCanAction("LftTrnLmpAtv", 1));
    ActionConsumer::getInstance()->pushBackAction(createSleepAction(500));

    ui->label_81->hide();
    ui->label_81->setText("");
    connect(MultiScreen::getInstance().get(), &MultiScreen::CallingTimerSignal, this, &MainWindow::handleCallingTimerSignal);

    ui->label_82->hide();
    ui->label_82->setText("");
    connect(MultiScreen::getInstance().get(), &MultiScreen::MusicTimerSignal, this, &MainWindow::handleMusicTimerSignal);

    ui->label_83->hide();
    ui->label_83->setText("");

    LogUpload::getInstance().get();
}

MainWindow::~MainWindow()
{
    itsOnlineTimer->stop();
    itsTimer->stop();
    delete ui;
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Up)
    {
        // sendSigWithName("VecChrgingSts", 0);
        qDebug() << "上 按下";
    }
    else if(event->key() == Qt::Key_Down)
    {
        // sendSigWithName("VecChrgingSts", 0);
    }
    else if(event->key() == Qt::Key_Enter)
    {
        sendSigWithName("MchnclStrWhSwOKBtn", 0);
    }
}


void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
    if (event->key() == Qt::Key_Up)
    {
        // sendSigWithName("VecChrgingSts", 1);
        qDebug() << "上 松开";
    }
    else if(event->key() == Qt::Key_Down)
    {
        // sendSigWithName("VecChrgingSts", 1);
    }
    else if(event->key() == Qt::Key_Enter)
    {
        sendSigWithName("MchnclStrWhSwOKBtn", 1);
    }
}

void MainWindow::onCheckOnlineTimeout()
{
    static int count = 0;
    if(CanRoute::getInstance()->isRouteRunning())
    {
        ui->isonline_checkBox->setChecked(true);
    }
    else
    {
        ui->isonline_checkBox->setChecked(false);
        if(CanRoute::getInstance()->start())
        {
            qDebug() << "Can device start success";
            count = 0;
        }
        else
        {
            count++;
            // qDebug() << "Can device start fail, try again:" << count;
        }
    }
}

void MainWindow::sendSigWithName(const char* sigName, int value)
{
    int msgId = CanRoute::getInstance()->getMsgIdBySigName(sigName);
    if(msgId != -1)
    {
        CanRoute::getInstance()->sendSignal(msgId, sigName, value);
        qDebug() << "Send : " << QString::number(msgId, 16).toUpper()  << " " << sigName  <<" SUCCESS";

        // 录制信号
        ActionConsumer::getInstance()->recording(sigName, value);
    }
    else
    {
        qDebug() << QString::number(msgId, 16).toUpper()  << " " << sigName  <<" not find";
    }
}

void MainWindow::on_LftTrnLmp_checkBox_clicked(bool checked)
{
    sendSigWithName("LftTrnLmpAtv", checked);
}


void MainWindow::on_RtTrnLmp_checkBox_clicked(bool checked)
{
    sendSigWithName("RtTrnLmpAtv", checked);
}


void MainWindow::on_airbag_checkBox_clicked(bool checked)
{
    sendSigWithName("AirbgIndOn", checked);
}

void MainWindow::on_checkBox_17_clicked(bool checked)
{
    sendSigWithName("VecChrgingSts", checked);
}


void MainWindow::on_checkBox_19_clicked(bool checked)
{
    sendSigWithName("NokeyFoundWrn", checked);
}


void MainWindow::on_checkBox_20_clicked(bool checked)
{
    sendSigWithName("PrsBrkToCrngWrn", checked);
}


void MainWindow::on_checkBox_35_clicked(bool checked)
{
    sendSigWithName("FobBatLwWrn", checked);
}


void MainWindow::on_checkBox_36_clicked(bool checked)
{
    sendSigWithName("AuthnFlrClsUIDToSSBWrn", checked);
}


void MainWindow::on_checkBox_41_clicked(bool checked)
{
    sendSigWithName("DoorLockWrn", checked);
}


void MainWindow::on_checkBox_58_clicked(bool checked)
{
    sendSigWithName("SSBBtnWrn", checked);
}


void MainWindow::on_checkBox_59_clicked(bool checked)
{
    sendSigWithName("VBatChrgStsIndOn", checked);
}


void MainWindow::on_checkBox_62_clicked(bool checked)
{
    sendSigWithName("KeyRmdWrn", checked);
}


void MainWindow::on_checkBox_63_clicked(bool checked)
{
    sendSigWithName("EleIndOfHyOccu", checked);
}


void MainWindow::on_checkBox_64_clicked(bool checked)
{
    sendSigWithName("HdOpenIndOn", checked);
}


void MainWindow::on_checkBox_65_clicked(bool checked)
{
    sendSigWithName("DDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_66_clicked(bool checked)
{
    sendSigWithName("PDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_67_clicked(bool checked)
{
    sendSigWithName("VecSOCLoWrngIndOn", checked);
}


void MainWindow::on_checkBox_29_clicked(bool checked)
{
    //READY
    sendSigWithName("VecStatRdy", checked);
}


void MainWindow::on_checkBox_21_clicked(bool checked)
{
    //后雾灯指示灯状态
    sendSigWithName("RrFogLmpsAct", checked);
}


void MainWindow::on_checkBox_22_clicked(bool checked)
{
    //远光灯
    sendSigWithName("HhBmIO", checked);
}


void MainWindow::on_checkBox_23_clicked(bool checked)
{
    //近光灯
    sendSigWithName("LwBmIO", checked);
}


void MainWindow::on_checkBox_25_clicked(bool checked)
{
    //EBD
    sendSigWithName("BrkProcInPrgrsIO", checked);
}


void MainWindow::on_checkBox_26_clicked(bool checked)
{
    //驾驶员侧车门状态
    sendSigWithName("DDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_27_clicked(bool checked)
{
    //右前侧车门状态
    sendSigWithName("PDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_28_clicked(bool checked)
{
    //左后侧车门状态
    sendSigWithName("LSDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_32_clicked(bool checked)
{
    //右后侧车门状态
    sendSigWithName("RSDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_33_clicked(bool checked)
{
    //车尾门状态
    sendSigWithName("TDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_34_clicked(bool checked)
{
    //充电口开启提示
    sendSigWithName("ChargPrtOpInOnPrmt", checked);
}


void MainWindow::on_checkBox_46_clicked(bool checked)
{
    //EPS
    sendSigWithName("PwrStrIo", checked);
}


void MainWindow::on_checkBox_44_clicked(bool checked)
{
    //ABS
    sendSigWithName("ABSIO", checked);
}


void MainWindow::on_checkBox_43_clicked(bool checked)
{
    //EVP 真空泵故障
    sendSigWithName("VacPumpWrngIndOn", checked);
}


void MainWindow::on_checkBox_42_clicked(bool checked)
{
    //驱动功率限制指示灯
    sendSigWithName("DrvPowLimtIndOn", checked);
}


void MainWindow::on_checkBox_39_clicked(bool checked)
{
    //12V蓄电池充电状态
    sendSigWithName("VBatChrgStsIndOn", checked);
}


void MainWindow::on_checkBox_40_clicked(bool checked)
{
    //整车绝缘报警指示灯
    sendSigWithName("VecIslateWrngIndOn", checked);
}

void MainWindow::on_checkBox_49_clicked(bool checked)
{
    //电机系统过热指示灯
    sendSigWithName("TMMCUOvheatIndOn", checked);
}

void MainWindow::on_checkBox_45_clicked(bool checked)
{
    //整车故障指示灯
    sendSigWithName("VecFltIndOn", checked);
}


void MainWindow::on_checkBox_47_clicked(bool checked)
{
    //动力电池温度异常指示
    sendSigWithName("PowBatTempAnormIndOn", checked);
}


void MainWindow::on_checkBox_53_clicked(bool checked)
{
    //动力电池故障指示
    sendSigWithName("PowBatErrIndOn", checked);
}


void MainWindow::on_checkBox_48_clicked(bool checked)
{
    //电机故障指示
    sendSigWithName("TMFltIndOn", checked);
}


void MainWindow::on_checkBox_50_clicked(bool checked)
{
    //能量回收指示
    sendSigWithName("EngyRevIndOn", checked);
}


void MainWindow::on_checkBox_54_clicked(bool checked)
{
    //电池包加热
    sendSigWithName("BatheatindON", checked);
}


void MainWindow::on_checkBox_18_clicked(bool checked)
{
    //充电状态
    sendSigWithName("VecChrgStsIndOn", checked);
}


void MainWindow::on_horizontalSlider_16_valueChanged(int value)
{
    //整车当前功率
    sendSigWithName("VecActPow", value);
}


void MainWindow::on_horizontalSlider_17_valueChanged(int value)
{
    //剩余充电时间
    sendSigWithName("ChrgRemainTim", value);
}


void MainWindow::on_checkBox_31_clicked(bool checked)
{
    //后位置灯
    sendSigWithName("TaPnLgtAtv", checked);
}


void MainWindow::on_horizontalSlider_11_valueChanged(int value)
{
    //大灯开关状态
    sendSigWithName("MaiLgtSw", value);
}


void MainWindow::on_checkBox_37_clicked(bool checked)
{
    //安全带有效性
    sendSigWithName("DrSbltAtcV", checked);
}


void MainWindow::on_checkBox_38_clicked(bool checked)
{
    //安装带状态
    sendSigWithName("DrSbltAtc", checked);
}


void MainWindow::on_checkBox_10_clicked(bool checked)
{
    //车速有效性
    sendSigWithName("VehSpdAvgDrvnV", checked);
}


void MainWindow::on_horizontalSlider_valueChanged(int value)
{
    //车速
    sendSigWithName("VehSpdAvgDrvn", value);
}


void MainWindow::on_checkBox_11_clicked(bool checked)
{
    //转速有效性
    sendSigWithName("VecTMActSpdV", checked);
}


void MainWindow::on_horizontalSlider_2_valueChanged(int value)
{
    //转速
    sendSigWithName("VecTMActSpd", value);
}


void MainWindow::on_checkBox_12_clicked(bool checked)
{
    //电量有效性
    sendSigWithName("VecSOCV", checked);
}


void MainWindow::on_horizontalSlider_3_valueChanged(int value)
{
    //电量
    sendSigWithName("VecSOC", value);
}


void MainWindow::on_checkBox_13_clicked(bool checked)
{
    //电流有效性
    sendSigWithName("VecActTalCurV", checked);
}


void MainWindow::on_horizontalSlider_4_valueChanged(int value)
{
    //电流
    sendSigWithName("VecActTalCur", value);
}


void MainWindow::on_checkBox_14_clicked(bool checked)
{
    //电压有效性
    sendSigWithName("VecActTalVolV", checked);
}


void MainWindow::on_horizontalSlider_5_valueChanged(int value)
{
    //电压
    sendSigWithName("VecActTalVol", value);
}


void MainWindow::on_horizontalSlider_6_valueChanged(int value)
{
    //整车当前功率百分比
    sendSigWithName("VecActPowPer", value);
}


void MainWindow::on_horizontalSlider_7_valueChanged(int value)
{
    //剩余续航历里程
    sendSigWithName("RemainOdo", value);
}


void MainWindow::on_checkBox_15_clicked(bool checked)
{
    //车辆行驶里程有效性
}


void MainWindow::on_horizontalSlider_8_valueChanged(int value)
{
    //车辆行驶里程
}


void MainWindow::on_checkBox_16_clicked(bool checked)
{
    //挡位有效性
    sendSigWithName("VecActGearStsV", checked);
}


void MainWindow::on_horizontalSlider_9_valueChanged(int value)
{
    //挡位
    sendSigWithName("VecActGearSts", value);
}


void MainWindow::on_horizontalSlider_12_valueChanged(int value)
{
    //驾驶模式
    sendSigWithName("VehDrvMod", value);
}


void MainWindow::on_dateEdit_dateTimeChanged(const QDateTime &dateTime)
{
    // 输出时间字符串
    sendSigWithName("Day", dateTime.date().year());
    sendSigWithName("Month", dateTime.date().month());
    sendSigWithName("Year", dateTime.date().day());
}


void MainWindow::on_checkBox_55_clicked(bool checked)
{
    sendSigWithName("GPSSystAtv", checked);
}


void MainWindow::on_horizontalSlider_18_valueChanged(int value)
{
    sendSigWithName("Hour", value);
}


void MainWindow::on_horizontalSlider_19_valueChanged(int value)
{
    sendSigWithName("Minute", value);
}


void MainWindow::on_horizontalSlider_20_valueChanged(int value)
{
    sendSigWithName("Second", value);
}


void MainWindow::on_checkBox_56_clicked(bool checked)
{
    sendSigWithName("TirePreSysWrngSts", checked);
}


void MainWindow::on_checkBox_57_clicked(bool checked)
{
    sendSigWithName("TirePreSysMalfSt", checked);
}


void MainWindow::on_horizontalSlider_13_valueChanged(int value)
{
    sendSigWithName("TirePreSysResSts", value);
}


void MainWindow::on_checkBox_60_clicked(bool checked)
{
    sendSigWithName("BlthConcetSts", checked);
}


void MainWindow::on_checkBox_61_clicked(bool checked)
{
    sendSigWithName("USBConcetSts", checked);
}


void MainWindow::on_horizontalSlider_14_valueChanged(int value)
{
    sendSigWithName("MltdVlmn", value);
}


void MainWindow::on_horizontalSlider_15_valueChanged(int value)
{
    sendSigWithName("ICEModeSts", value);
}


void MainWindow::on_checkBox_73_clicked(bool checked)
{
    sendSigWithName("TDAjrSwAtv", checked);
}


void MainWindow::on_checkBox_74_clicked(bool checked)
{
    sendSigWithName("ChargPrtOpInOnPrmt", checked);
}


void MainWindow::on_checkBox_72_clicked(bool checked)
{
    //spi信息
}


void MainWindow::on_checkBox_71_clicked(bool checked)
{
    sendSigWithName("VCUBatThrmlRunwyAlmInd", checked);
}


void MainWindow::on_checkBox_68_clicked(bool checked)
{
    sendSigWithName("VecChrgStsIndOn", checked);
}


void MainWindow::on_checkBox_78_clicked(bool checked)
{
    sendSigWithName("VecChrgStsIndOn", checked);
}


void MainWindow::on_checkBox_69_clicked(bool checked)
{

}


void MainWindow::on_checkBox_77_clicked(bool checked)
{
    sendSigWithName("VehiStarWarning", checked);
}


void MainWindow::on_checkBox_75_clicked(bool checked)
{
    sendSigWithName("PlePullHandBraWhenChar", checked);
}


void MainWindow::on_checkBox_70_clicked(bool checked)
{
    sendSigWithName("ShifGearFailAtNobrak", checked);
}


void MainWindow::on_checkBox_79_clicked(bool checked)
{
    sendSigWithName("NoPulOutChrgPlugWrng", checked);
}


void MainWindow::on_checkBox_87_clicked(bool checked)
{
    sendSigWithName("BatheatindOn", checked);
}


void MainWindow::on_checkBox_127_clicked(bool checked)
{
    sendSigWithName("VecChrgingSts", checked);
}


void MainWindow::on_checkBox_128_clicked(bool checked)
{
    sendSigWithName("VecChrgStsIndOn", checked);
}


void MainWindow::on_checkBox_82_clicked(bool checked)
{
    //undefine
}


void MainWindow::on_checkBox_89_clicked(bool checked)
{
    //undefine
}

void MainWindow::on_comboBox_currentIndexChanged(int index)
{
    sendSigWithName("EPBSysDspMsgReq", index);
}


void MainWindow::on_checkBox_90_clicked(bool checked)
{
    sendSigWithName("EPBSysDspMsgReqV", checked);
}


void MainWindow::on_checkBox_85_clicked(bool checked)
{
    sendSigWithName("TirePreSysWrngSts", checked);
}



void MainWindow::on_comboBox_2_currentIndexChanged(int index)
{
    sendSigWithName("SCUWar", index);
}


void MainWindow::on_comboBox_3_currentIndexChanged(int index)
{
    sendSigWithName("ShftIncrtOptnIndctn", index);
}


void MainWindow::on_comboBox_4_currentIndexChanged(int index)
{
    sendSigWithName("TirePreSysResSts", index);
}


void MainWindow::on_checkBox_98_clicked(bool checked)
{
    sendSigWithName("ChrgACOpenPmpt", checked);
}


void MainWindow::on_checkBox_112_clicked(bool checked)
{
    sendSigWithName("NGrAnTchSetSts", checked);
    sendSigWithName("NGrAnTchPmpt", checked);
}


void MainWindow::on_checkBox_105_clicked(bool checked)
{
    sendSigWithName("EmgSwOff", checked);
}

void MainWindow::on_comboBox_5_currentIndexChanged(int index)
{
    sendSigWithName("VehModIndRqst", index);
}


void MainWindow::on_checkBox_30_clicked(bool checked)
{
    int value = checked ? 2 : 0;
    sendSigWithName("EBSWrngIndOn", value);
    sendSigWithName("VehBrkBstStsWrng", value);
}


void MainWindow::on_checkBox_80_clicked(bool checked)
{
    int value = checked ? 2 : 0;
    sendSigWithName("RCWSwSetSts", value);
    sendSigWithName("RCWAlmRqst", checked);
}


void MainWindow::on_checkBox_81_clicked(bool checked)
{
    sendSigWithName("DrTakovRqst", checked);
}


void MainWindow::on_comboBox_6_currentIndexChanged(int index)
{
    sendSigWithName("WrngLvl", index);
}


void MainWindow::on_comboBox_7_currentIndexChanged(int index)
{
    sendSigWithName("CECUPrmtLvlA", index);
}


void MainWindow::on_comboBox_8_currentIndexChanged(int index)
{
    int value = 0;
    switch(index)
    {
        case 0:
            value = 0x12;
            break;

        case 1:
            value = 0x15;
            break;

        case 2:
            value = 0x16;
            break;
        default:
                break;
    }

    sendSigWithName("CECUPrmtLvlB", value);
}


void MainWindow::on_comboBox_9_currentIndexChanged(int index)
{
    sendSigWithName("URCWrngVicRqst", index);
}


void MainWindow::on_comboBox_10_currentIndexChanged(int index)
{
    sendSigWithName("PrkAssSndCadCom", index);
}


void MainWindow::on_checkBox_99_clicked(bool checked)
{
    sendSigWithName("OvspdWrn", checked);
}


void MainWindow::on_comboBox_11_currentIndexChanged(int index)
{
    sendSigWithName("DTLCSts", index);
}


void MainWindow::on_comboBox_12_currentIndexChanged(int index)
{
    sendSigWithName("DTLCTgtPstnMsgWrn", index);
}


void MainWindow::on_checkBox_83_clicked(bool checked)
{
    sendSigWithName("TMOvSpIndOn", checked);
}


void MainWindow::on_checkBox_84_clicked(bool checked)
{
    sendSigWithName("DriverLeftWarning", checked);
}


void MainWindow::on_checkBox_86_clicked(bool checked)
{
    sendSigWithName("DrSbltAtc", checked);
}


void MainWindow::on_checkBox_88_clicked(bool checked)
{
    sendSigWithName("DrivStOccSt", checked);
}


void MainWindow::on_checkBox_52_clicked(bool checked)
{

}


void MainWindow::on_comboBox_13_currentIndexChanged(int index)
{
    sendSigWithName("VehModCntRqst", index);
}


void MainWindow::on_pushButton_pressed()
{
    sendSigWithName("MchnclStrWhSwOKBtn", 1);
}


void MainWindow::on_pushButton_released()
{
    sendSigWithName("MchnclStrWhSwOKBtn", 0);
}


void MainWindow::on_comboBox_14_currentIndexChanged(int index)
{
    sendSigWithName("ThFrtPrbWrngRqst", index);
}


void MainWindow::on_comboBox_15_currentIndexChanged(int index)
{
    sendSigWithName("ThScdPrbWrngRqst", index);
}


void MainWindow::on_comboBox_17_currentIndexChanged(int index)
{

    sendSigWithName("ThTrdPrbWrngRqst", index);
}


void MainWindow::on_comboBox_16_currentIndexChanged(int index)
{

    sendSigWithName("ThFuhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_21_currentIndexChanged(int index)
{

    sendSigWithName("ThFfhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_18_currentIndexChanged(int index)
{

    sendSigWithName("ThSxhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_19_currentIndexChanged(int index)
{

    sendSigWithName("ThSvhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_20_currentIndexChanged(int index)
{

    sendSigWithName("ThEghPrbWrngRqst", index);
}


void MainWindow::on_comboBox_22_currentIndexChanged(int index)
{

    sendSigWithName("ThNnhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_23_currentIndexChanged(int index)
{

    sendSigWithName("ThTnhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_25_currentIndexChanged(int index)
{

    sendSigWithName("ThEvhPrbWrngRqst", index);
}


void MainWindow::on_comboBox_24_currentIndexChanged(int index)
{

    sendSigWithName("ThTfhPrbWrngRqst", index);
}

void MainWindow::on_horizontalSlider_10_valueChanged(int value)
{
    sendSigWithName("FntPrbNrtDist", value);
}


void MainWindow::on_horizontalSlider_21_valueChanged(int value)
{
    sendSigWithName("RrPrbNrtDist", value);
}


void MainWindow::on_checkBox_76_clicked(bool checked)
{
    sendSigWithName("FtPnLgtAtv", checked);
}


void MainWindow::on_checkBox_91_clicked(bool checked)
{
    sendSigWithName("EPBSysStatIndReqV", checked);
}


void MainWindow::on_checkBox_92_clicked(bool checked)
{
    sendSigWithName("EPBSysWrnIndReqV", checked);
}

void MainWindow::on_comboBox_26_currentIndexChanged(int index)
{
    sendSigWithName("EPBSysWrnIndReq", index);
}


void MainWindow::on_comboBox_27_currentIndexChanged(int index)
{
    sendSigWithName("EPBSysStatIndReq", index);
}


void MainWindow::on_comboBox_28_currentIndexChanged(int index)
{
    sendSigWithName("VehStabEnhmntStat", index);
}


void MainWindow::on_checkBox_93_clicked(bool checked)
{
    sendSigWithName("VSESysOffIO", checked);
}


void MainWindow::on_comboBox_29_currentIndexChanged(int index)
{
    sendSigWithName("TraLgt", index);
}


void MainWindow::on_checkBox_94_clicked(bool checked)
{
    sendSigWithName("ADASCtrlSts", checked);
}


void MainWindow::on_checkBox_95_clicked(bool checked)
{
    sendSigWithName("ADASIndReq", checked);
}


void MainWindow::on_comboBox_30_currentIndexChanged(int index)
{
    sendSigWithName("AEBFCWSwSetSts", index);
}


void MainWindow::on_checkBox_96_clicked(bool checked)
{
    sendSigWithName("AEBEnable", checked);
}


void MainWindow::on_comboBox_31_currentIndexChanged(int index)
{
    sendSigWithName("FCWAlm", index);
}


void MainWindow::on_horizontalSlider_22_valueChanged(int value)
{
    sendSigWithName("ACCSetSpd", value);
}


void MainWindow::on_comboBox_32_currentIndexChanged(int index)
{
    sendSigWithName("ACCOptSts", index);
}


void MainWindow::on_comboBox_33_currentIndexChanged(int index)
{
    sendSigWithName("ADASWkIndLt", index);
}


void MainWindow::on_comboBox_35_currentIndexChanged(int index)
{
    sendSigWithName("LtlCtrlSts", index);
}


void MainWindow::on_comboBox_34_currentIndexChanged(int index)
{
    sendSigWithName("TJAWkSts", index);
}


void MainWindow::on_comboBox_36_currentIndexChanged(int index)
{
    sendSigWithName("EngyRevIntensSetSts", index);
}

void MainWindow::on_horizontalSlider_23_valueChanged(int value)
{
    sendSigWithName("TICENtwkTemp", value);
}


void MainWindow::on_horizontalSlider_24_valueChanged(int value)
{
    sendSigWithName("AvgPowConsmp_50km", value);
}


void MainWindow::on_checkBox_100_clicked(bool checked)
{
    sendSigWithName("MaxSpdLmtStsFb", checked);
}


void MainWindow::on_horizontalSlider_26_valueChanged(int value)
{
    sendSigWithName("MaxSpdLmtVal", value);
}


void MainWindow::on_horizontalSlider_25_valueChanged(int value)
{
    sendSigWithName("TraSigReco", value);
}


void MainWindow::on_checkBox_97_clicked(bool checked)
{
    sendSigWithName("OvspdWrn", checked);
}


void MainWindow::on_comboBox_38_currentIndexChanged(int index)
{
    sendSigWithName("SpdLimtWrngSwSetSts", index);
}


void MainWindow::on_checkBox_101_clicked(bool checked)
{
    sendSigWithName("CrsCntAtv", checked);
}


void MainWindow::on_checkBox_102_clicked(bool checked)
{
    sendSigWithName("CrsCntEnbld", checked);
}


void MainWindow::on_checkBox_103_clicked(bool checked)
{
    sendSigWithName("CrsCntlDrSelSpdAct", checked);
}


void MainWindow::on_horizontalSlider_27_valueChanged(int value)
{
    sendSigWithName("CrsCntlDrSelSpd", value);
}


void MainWindow::on_RtTrnLmp_checkBox_2_clicked(bool checked)
{
    sendSigWithName("LftTrnLmpAtv", checked);
    sendSigWithName("RtTrnLmpAtv", checked);
}



void MainWindow::on_horizontalSlider_28_valueChanged(int value)
{
    sendSigWithName("InsrtScrnBcklgtSwngRqst", value);
}



void MainWindow::on_comboBox_37_currentIndexChanged(int index)
{
    sendSigWithName("InsrtScrnBcklgtSwngRqst", index);
}


void MainWindow::on_pushButton_2_clicked(bool checked)
{

}


void MainWindow::on_pushButton_3_clicked()
{

}


void MainWindow::on_pushButton_2_clicked()
{

}


void MainWindow::on_pushButton_2_pressed()
{
    sendSigWithName("MchnclStrWhSwUpBtn", 1);
}


void MainWindow::on_pushButton_2_released()
{
    sendSigWithName("MchnclStrWhSwUpBtn", 0);
}


void MainWindow::on_pushButton_3_pressed()
{
    sendSigWithName("MchnclStrWhSwDwnBtn", 1);
}


void MainWindow::on_pushButton_3_released()
{
    sendSigWithName("MchnclStrWhSwDwnBtn", 0);
}


void MainWindow::on_comboBox_39_currentIndexChanged(int index)
{
    sendSigWithName("ICThmSetRqst", index);
}


void MainWindow::on_LftTrnLmp_checkBox_2_clicked(bool checked)
{
    sendSigWithName("AVHStatIndReqV", checked);
}


void MainWindow::on_RtTrnLmp_checkBox_3_clicked(bool checked)
{
    sendSigWithName("AVHStatIndReq", checked);
}


void MainWindow::on_checkBox_104_clicked(bool checked)
{
    sendSigWithName("ImmoFlrWrn", checked);
}


void MainWindow::on_checkBox_106_clicked(bool checked)
{
    if(checked)
    {
        sendSigWithName("SysPowMode", 2);
    }
    else
    {
        sendSigWithName("SysPowMode", 1);
    }
}

void MainWindow::on_pushButton_6_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(nullptr,
                                                    "Open File",
                                                    "C:\\Users\\Public\\Documents",
                                                    "Text Files (*.json);");

    if (!fileName.isEmpty())
    {
        ui->lineEdit->setText(fileName);
        ActionConsumer::getInstance()->parseJsonAsAction(fileName.toStdString().c_str());
    }
    else
    {
        ui->lineEdit->setText("无效路径");
    }
}

void MainWindow::on_checkBox_107_clicked(bool checked)
{
    if(checked)
    {
        ActionConsumer::getInstance()->playOnce();
    }
    else
    {
        ActionConsumer::getInstance()->stopPlay();
    }
}

void MainWindow::on_checkBox_108_clicked(bool checked)
{
    if(checked)
    {
        ActionConsumer::getInstance()->playLoop();
    }
    else
    {
        ActionConsumer::getInstance()->stopPlay();
    }
}


void MainWindow::on_checkBox_109_clicked(bool checked)
{
    if(checked)
    {
        ActionConsumer::getInstance()->startRecord();
    }
    else
    {
        ActionConsumer::getInstance()->stopRecord();
    }
}

void MainWindow::on_pushButton_7_clicked()
{
    if(MultiScreen::getInstance()->startHttpServer())
    {
        ui->pushButton_7->setText("停止");
    }
    else
    {
        ui->pushButton_7->setText("启动");
        QApplication::processEvents();
    }
}

void MainWindow::on_pushButton_10_clicked()
{
    if(MultiScreen::getInstance()->connectHuServer())
    {
        ui->pushButton_10->setText("断开连接");
    }
    else
    {
        ui->pushButton_10->setText("连接仪表");
    }
}

void MainWindow::on_pushButton_8_clicked()
{
    if(MultiScreen::getInstance()->playMusic())
    {
        ui->pushButton_8->setText("暂停");
    }
    else
    {
        ui->pushButton_8->setText("播放");
    }
}

void MainWindow::on_pushButton_11_clicked()
{
    if(MultiScreen::getInstance()->callOut())
    {
        ui->pushButton_11->setText("停止通话");
    }
    else
    {
        ui->label_83->setText("通话结束");
    }
}

void MainWindow::handleCallingTimerSignal(int status, const QString &message)
{
    qDebug() << "handleCallingTimerSignal" << status << message;
    switch (status)
    {
        case 0: // 空闲状态
        ui->pushButton_11->setText("拨打电话");
        ui->label_81->hide();
        ui->label_83->hide();
        break;

        case 1: // 呼叫中
        ui->label_83->setText("正在呼叫");
        ui->label_83->show();
        break;

        case 2: // 振铃中
        ui->label_83->setText("正在振铃");
        ui->label_83->show();
        break;

        case 3: // 通话中
        ui->label_83->setText("正在通话");
        ui->label_83->show();

        ui->label_81->setText(message);
        ui->label_81->show();
        break;

        case 4: // 通话挂断
        ui->pushButton_11->setText("拨打电话");

        ui->label_81->hide();
        ui->label_83->hide();
        break;

        case 0xff: // 网络中断
        ui->pushButton_11->setText("拨打电话");
        ui->label_81->hide();
        ui->label_83->hide();
        ui->pushButton_10->setText("连接仪表");
        break;

        default:
            break;
    }
}

void MainWindow::handleMusicTimerSignal(bool status, bool Connect, const QString &message)
{
    if(Connect)
    {
        if(status)
        {
            qDebug() << "handleMusicTimerSignal" << status << message;
            ui->label_82->setText(message);
            ui->label_82->show();
        }
        else
        {
            qDebug() << "handleMusicTimerSignal";
            ui->pushButton_8->setText("播放");
            ui->label_82->hide();
        }
    }
    else
    {
        ui->pushButton_8->setText("播放");
        ui->label_82->hide();

        ui->pushButton_11->setText("拨打电话");
        ui->label_81->hide();
        ui->label_83->hide();
        ui->pushButton_10->setText("连接仪表");
    }
}

void MainWindow::on_pushButton_9_clicked()
{
    MultiScreen::getInstance()->nextMusic();
}

void MainWindow::on_checkBox_24_clicked(bool checked)
{
    sendSigWithName("SbtlOdoInfmtnClr", checked);
}


void MainWindow::on_pushButton_12_clicked()
{
    qDebug() << "获取日志";
    LogUpload::getInstance()->LogRequest();
}

